import { ElMessage } from 'element-plus'
const action = {
    /**
  * 操作警告提示
  */
    warning: function (message, showClose = true) {
        ElMessage({
            message: message,
            showClose: showClose,
            type: 'warning',
        })
    },
    /**
 * 操作成功提示
 */
    success: function (message, showClose = true) {
        ElMessage({
            message: message,
            showClose: showClose,
            type: 'success',
        })
    },
    error: function (message, showClose = true) {
        ElMessage({
            message: message,
            showClose: showClose,
            type: 'error',
        })
    },
    grouping: function (message, type, showClose = true) {
        ElMessage({
            message: message,
            grouping: true,
            showClose: showClose,
            type: type,
        })
    },
    /**
 * 下载
 */
    download: function (data, fileName, responseType = 'application/octet-stream') {
        const blob = data instanceof Blob ? data : new Blob([data], { type: responseType })
        if ('download' in document.createElement('a')) { // 非IE下载
            const url = window.URL.createObjectURL(blob)
            const link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName)
            document.body.appendChild(link)
            link.click()
            window.URL.revokeObjectURL(link.href)
            document.body.removeChild(link)
        } else { // IE10+下载
            navigator.msSaveBlob(blob, fileName)
        }
    },

    /**
   * 导出文件
   */
    exportFile: function (data, fileName, responseType = 'application/octet-stream') {
        this.download(data, fileName, responseType)
    }
}
export default action